package com.yy.bolg.service.impl;

import com.yy.bolg.dao.TestingAccessoryDao;
import com.yy.bolg.entity.TestingAccessoryBean;
import com.yy.bolg.exception.LackParameterException;
import com.yy.bolg.exception.OtherThingsException;
import com.yy.bolg.service.TestingAccessoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 检测所选附件Service实现类，对接口里的方法进行构造填充
 * @author enmaoFu
 * @date 2024-11-12
 */
@Service("testingAccessoryService")
public class TestingAccessoryServiceImpl implements TestingAccessoryService {

    @Autowired
    private TestingAccessoryDao testingAccessoryDao;

    @Override
    public void add(TestingAccessoryBean bean) throws Exception {
        if(StringUtils.isEmpty(bean.getPsTestingCode())){
            throw new LackParameterException("检测编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsAccessoryCode())){
            throw new LackParameterException("附件编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsAccessoryName())){
            throw new LackParameterException("附件名称不能为空");
        }

        if(bean.getPsAccessoryPrice() <= 0){
            throw new LackParameterException("附件单价不合法");
        }

        if(StringUtils.isEmpty(bean.getPsAccessoryClassCode())){
            throw new LackParameterException("附件分类编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsAccessoryClassName())){
            throw new LackParameterException("附件分类名称不能为空");
        }

        if(bean.getPsTestingAccessoryNumber() <= 0){
            throw new LackParameterException("所选附件数量不合法");
        }

        try {
            testingAccessoryDao.add(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OtherThingsException("添加数据失败");
        }
    }

    @Override
    public List<TestingAccessoryBean> findAllByCondition(TestingAccessoryBean bean) throws Exception {
        try {
            return testingAccessoryDao.findAllByCondition(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new LackParameterException(e.getMessage());
        }
    }
}
